<?php
require_once 'app/bootstrap.php';

$phone          = isset($_GET['phone']) ? $_GET['phone'] : null;
$phone          = Helper_Advert::dbFormatPhone($phone);

$realtorStatus  = isset($_GET['realtor']) ? (int) $_GET['realtor'] : null;
$result = false;
if ($phone && ($_SERVER['REMOTE_ADDR'] == '80.92.227.82' || $_SERVER['REMOTE_ADDR'] == '178.150.165.190')) {
    $dbPhone            = new Model_Resource_Phone();
    $dbPhoneRelations   = new Model_Resource_Phone_Phone();
    $phoneRow = $dbPhone->fetchRowByPhone($phone);
    if (null !== $phoneRow) {
        $phoneId = $phoneRow->id;
        $relations = $dbPhoneRelations->fetchAll('phone_id = ' . (int) $phoneId);
        $phones = array($phoneId);
        foreach ($relations as $row) {
            $phones[] = $row->related_phone_id;
        }
        $where = $dbPhone->getAdapter()->quoteInto('id IN (?)', $phones, Zend_Db::INT_TYPE);
        $result = $dbPhone->update(array('realtor' => $realtorStatus), $where);
    }
}

echo json_encode((bool)$result);

